package com.cy.model;

import com.alibaba.fastjson.JSONObject;
import com.cy.BasicModel;
import com.cy.ext.plugin.tablebind.TableBind;

import java.util.Date;
import java.util.List;

@SuppressWarnings("serial")
@TableBind(tableName="user_map_role",pkName = "id")
public class UserMapRole extends BasicModel<UserMapRole> {
    public static final UserMapRole dao = new UserMapRole();
    public static final String SELECT_ALL = "`id`,`user_id`,`role_id`,`create_time`,`statue`,`user_role_level`";

    /**
     * 工种
     */
    public enum Level{
        MANAGER(0, "督导经理"),
        PRODUCER_TESTER(1, "生产与测试人员");

        private int value;
        private String name;

        Level(int value, String name) {
            this.value = value;
            this.name = name;
        }

        public String getName() {
            return name;
        }

        public int getValue() {
            return value;
        }

        public static JSONObject toJson(){
            JSONObject jsonObject = new JSONObject(values().length);
            for (Level item : values())
                jsonObject.put(String.valueOf(item.getValue()), item.getName());
            return jsonObject;
        }
    }

    public List<UserMapRole> findByUser(long userId){
        return find("SELECT * FROM user_map_role WHERE user_id =? ",userId);
    }
    public UserMapRole findExistsRole(long userId ,long roleId){
        return findFirst("SELECT * FROM user_map_role WHERE user_id =? AND role_id =? ",userId,roleId);
    }

    public UserMapRole setUserRoleLevel(Long userRoleLevel){
        this.set("user_role_level", userRoleLevel);
        return this;
    }

    public Long getUserRoleLevel(){
        return this.getLong("user_role_level");
    }

    public UserMapRole setId (Long id){
        this.set("id",id);
        return this;
    }

    public Long getId (){
        return this.get("id");
    }

    public UserMapRole setUserId (Long userId){
        this.set("user_id",userId);
        return this;
    }

    public Long getUserId (){
        return this.get("user_id");
    }

    public UserMapRole setRoleId (Long roleId){
        this.set("role_id",roleId);
        return this;
    }

    public Long getRoleId (){
        return this.get("role_id");
    }

    public UserMapRole setCreateTime (Date createTime){
        this.set("create_time",createTime);
        return this;
    }

    public Date getCreateTime (){
        return this.getDate("create_time");
    }

    public UserMapRole setStatue (Integer statue){
        this.set("statue",statue);
        return this;
    }

    public Integer getStatue (){
        return this.get("statue");
    }
}